package com.ruoyi.safe.controller.web;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.safe.domain.BizExcludePlanTask;
import com.ruoyi.safe.domain.dto.BizExcludePlanTaskDTO;
import com.ruoyi.safe.service.IBizExcludePlanTaskService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 自动生成任务Controller
 *
 * @author buxi
 * @date 2023-11-23
 */
@RestController
@RequestMapping("/plan/task")
@AllArgsConstructor
public class BizExcludePlanTaskController extends BaseController {

    private final IBizExcludePlanTaskService bizExcludePlanTaskService;

    /**
     * 查询自动生成任务列表
     */
    @PreAuthorize("@ss.hasPermi('plan:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizExcludePlanTask bizExcludePlanTask) {
        startPage();
        List<BizExcludePlanTask> list = bizExcludePlanTaskService.selectBizExcludePlanTaskList(bizExcludePlanTask);
        return getDataTable(list);
    }

    /**
     * 导出自动生成任务列表
     */
    @PreAuthorize("@ss.hasPermi('plan:task:export')")
    @Log(title = "自动生成任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizExcludePlanTask bizExcludePlanTask) {
        List<BizExcludePlanTask> list = bizExcludePlanTaskService.selectBizExcludePlanTaskList(bizExcludePlanTask);
        ExcelUtil<BizExcludePlanTask> util = new ExcelUtil<>(BizExcludePlanTask.class);
        util.exportExcel(response, list, "自动生成任务数据");
    }
    /**
     * 批量生成代办任务
     */
    @Log(title = "批量生成代办任务", businessType = BusinessType.INSERT)
    @GetMapping("/add")
    public AjaxResult add(BizExcludePlanTaskDTO bizExcludePlanTaskDTO) {
        return success(bizExcludePlanTaskService.insertBizExcludePlanTaskBatch(bizExcludePlanTaskDTO));
    }
    /**
     * 取消生成代办任务
     */
    @Log(title = "取消生成代办任务", businessType = BusinessType.DELETE)
    @PutMapping("/cancel")
    public AjaxResult cancel(BizExcludePlanTaskDTO bizExcludePlanTaskDTO) {
        return success(bizExcludePlanTaskService.cancelBizExcludePlanTaskBatch(bizExcludePlanTaskDTO));
    }

}
